package com.example.androidcoursedesing.login;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.androidcoursedesing.R;
import com.example.androidcoursedesing.login.utils.Utils;


public class RegisterAct extends AppCompatActivity implements View.OnClickListener {
    ImageView registeractivity_back;
    EditText et_registeractivity_username;
    EditText et_registeractivity_password1;
    EditText et_registeractivity_password2;
    EditText et_registeractivity_phone;
    EditText et_registeractivity_email;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        registeractivity_back = findViewById(R.id.iv_registeractivity_back);
        Button bt_registeractivity_register = findViewById(R.id.bt_registeractivity_register);
        et_registeractivity_username = findViewById(R.id.et_registeractivity_username);
        et_registeractivity_password1 = findViewById(R.id.et_registeractivity_password1);
        et_registeractivity_password2 = findViewById(R.id.et_registeractivity_password2);
        et_registeractivity_phone = findViewById(R.id.et_registeractivity_phone);
        et_registeractivity_email = findViewById(R.id.et_registeractivity_email);
         registeractivity_back.setOnClickListener(this);
        bt_registeractivity_register.setOnClickListener(this);




    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_registeractivity_back:
                //点击返回按钮就关闭该界面
                RegisterAct.this.finish();
                break;
            case R.id.bt_registeractivity_register:

                String username = et_registeractivity_username.getText().toString();
                String password1 = et_registeractivity_password1.getText().toString();
                String password2 = et_registeractivity_password2.getText().toString();
                String phone = et_registeractivity_phone.getText().toString();
                String email = et_registeractivity_email.getText().toString();

                if (!password1.equals(password2)){//校验密码是否一致
                    Toast.makeText(this, "密码不一致" , Toast.LENGTH_SHORT).show();
                    return;
                }

                if (!Utils.isMobile(phone)){//校验手机号
                    Toast.makeText(this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (!Utils.checkEmail(email)){//校验邮箱地址
                    Toast.makeText(this, "请输入正确的邮箱地址", Toast.LENGTH_SHORT).show();
                    return;
                }

                UserBean userBean = new UserBean();
                userBean.setUsername(username);
                userBean.setPassword(password1);
                userBean.setPhone(phone);
                userBean.setEmail(email);
                //实现注册



                break;


        }

    }
}
